# This files contains your custom actions which can be used to run
# custom Python code.
#
# See this guide on how to implement these action:
# https://rasa.com/docs/rasa/custom-actions


# This is a simple example for a custom action which utters "Hello World!"

from typing import Any, Text, Dict, List

from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher

foods = ['鱼香肉丝', '宫保鸡丁', '蛋炒饭', '西红柿炒鸡蛋']


class ActionHelloWorld(Action):

    def name(self) -> Text:
        return "action_hello_world"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
        dispatcher.utter_message(text="Hello World!")

        return []


class ActionMkFriend(Action):

    def name(self) -> Text:
        return "action_mkfriend"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
        username = tracker.get_slot("username")
        if username is None:
            username = "朋友"
        dispatcher.utter_message("您好，" + username + "!")
        return []


class ActionAskFood(Action):

    def name(self) -> Text:
        return "action_ask_food"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
        menu = '我们这里有'
        for food in foods:
            menu += food + '、'
        menu = menu[:-1] + '。'
        dispatcher.utter_message(menu)
        return []
